<tr data-assembly-id="<%= assembly.id %>" data-parent-id="<%= assembly.parent_id %>" data-level="<%= assembly.ancestors.count %>">
  <td class="whitespace-nowrap" data-label="<%= t("models.assembly.fields.title", scope: "decidim.admin") %>">
    <% if parent_assembly_id %>
      <% [assembly.ancestors.count - 1, 0].max.times do |index| %>
        <span class="px-3"></span>
      <% end %>
      <span class="px-3 text-xl text-secondary opacity-10">|</span>
    <% end %>

    <% if assembly.promoted? %>
      <%= icon_with_tooltip "star-s-fill", t("models.assembly.fields.promoted", scope: "decidim.admin") %>
    <% end %>

    <span class="table-list__title-ellipsis">
      <% if allowed_to? :update, :assembly, assembly: assembly %>
        <%= link_to translated_attribute(assembly.title), edit_assembly_path(assembly) %>
      <% elsif allowed_to? :read, :component, assembly: assembly %>
        <%= link_to translated_attribute(assembly.title), components_path(assembly) %><br>
      <% else %>
        <%= translated_attribute(assembly.title) %>
      <% end %>
    </span>

    <% if assembly.children.count.positive? %>
      <%= link_to url_for(query_params_with(parent_id_eq: assembly.id)), remote: true, data: { arrow_down: true } do %>
        <%= icon "arrow-down-s-line", class: "w-4 h-4 ml-2" %>
      <% end %>
      <%= link_to "#", class: "hidden", data: { arrow_up: true } do %>
        <%= icon "arrow-up-s-line", class: "w-4 h-4 ml-2" %>
      <% end %>
    <% end %>
  </td>
  <td class="table-list__date" data-label="<%= t("models.assembly.fields.created_at", scope: "decidim.admin") %>">
    <%= l(assembly.created_at, format: :short) %>
  </td>
  <td class="table-list__state" data-label="<%= t("models.assembly.fields.private", scope: "decidim.admin") %>">
    <% if assembly.private_space? %>
      <span><%= t("assemblies.index.private", scope: "decidim.admin") %></span>
    <% else %>
      <span><%= t("assemblies.index.public", scope: "decidim.admin") %></span>
    <% end %>
  </td>
  <td class="table-list__state" data-label="<%= t("models.assembly.fields.published", scope: "decidim.admin") %>">
    <% if assembly.published? %>
      <span class="label success !text-sm"><%= t("assemblies.index.published", scope: "decidim.admin") %></span>
    <% else %>
      <span class="label alert !text-sm"><%= t("assemblies.index.unpublished", scope: "decidim.admin") %></span>
    <% end %>
  </td>
  <td class="table-list__actions" data-label="<%= t("models.assembly.fields.actions", scope: "decidim.admin") %>">
    <button type="button" data-controller="dropdown" data-target="actions-assembly-<%= assembly.id %>" aria-label="<%= t("decidim.admin.actions.actions_label", resource: translated_attribute(assembly.title)) %>">
      <%= icon "more-fill", class: "text-secondary" %>
    </button>

    <div class="inline-block relative">
      <ul id="actions-assembly-<%= assembly.id %>" class="dropdown dropdown__action" aria-hidden="true">
        <% if view == :deleted %>
          <% if allowed_to? :restore, :assembly, trashable_deleted_resource: assembly %>
            <li class="dropdown__item">
              <%= link_to restore_assembly_path(assembly), class: "dropdown__button", method: :patch do %>
                <%= icon "refresh-line" %>
                <%= t("actions.restore", scope: "decidim.admin") %>
              <% end %>
            </li>
          <% end %>
        <% else %>
          <% if allowed_to? :update, :assembly, assembly: assembly %>
            <li class="dropdown__item">
              <%= link_to edit_assembly_path(assembly), class: "dropdown__button" do %>
                <%= icon "pencil-line" %>
                <%= t("actions.edit", scope: "decidim.admin") %>
              <% end %>
            </li>
          <% end %>

          <hr>

          <% if allowed_to? :duplicate, :assembly, assembly: assembly %>
            <li class="dropdown__item">
              <%= link_to new_assembly_duplicate_path(assembly), class: "dropdown__button" do %>
                <%= icon "file-copy-line" %>
                <%= t("actions.duplicate", scope: "decidim.admin") %>
              <% end %>
            </li>
          <% end %>

          <% if allowed_to? :export, :assembly, assembly: assembly %>
            <li class="dropdown__item">
              <%= link_to assembly_export_path(assembly), class: "dropdown__button", method: :post do %>
                <%= icon "download-line" %>
                <%= t("actions.export", scope: "decidim.admin") %>
              <% end %>
            </li>
          <% end %>

          <hr>

          <% if allowed_to? :preview, :assembly, assembly: assembly %>
            <li class="dropdown__item">
              <%= link_to decidim_assemblies.assembly_path(assembly, locale: current_locale), class: "dropdown__button", target: "_blank", data: { "external-link": false } do %>
                <%= icon "eye-line" %>
                <%= t("actions.preview", scope: "decidim.admin") %>
              <% end %>
            </li>
          <% end %>

          <% if allowed_to? :read, :share_token, current_participatory_space: assembly %>
            <li class="dropdown__item">
              <%= link_to decidim_admin_assemblies.assembly_share_tokens_path(assembly), class: "dropdown__button" do %>
                <%= icon "share-line" %>
                <%= t("actions.share_tokens", scope: "decidim.admin") %>
              <% end %>
            </li>
          <% end %>

          <% if allowed_to? :publish, :assembly, assembly: assembly %>
            <li class="dropdown__item">
              <% if assembly.published? %>
                <%= link_to assembly_publish_path(assembly), method: :delete, class: "dropdown__button" do %>
                  <%= icon "close-circle-line" %>
                  <%= t("actions.unpublish", scope: "decidim.admin") %>
                <% end %>
              <% else %>
                <%= link_to assembly_publish_path(assembly), method: :post, class: "dropdown__button" do %>
                  <%= icon "check-line" %>
                  <%= t("actions.publish", scope: "decidim.admin") %>
                <% end %>
              <% end %>
            </li>
          <% end %>

          <hr>

          <% if allowed_to? :read, :moderation, assembly: assembly %>
            <li class="dropdown__item">
              <%= link_to moderations_path(assembly), class: "dropdown__button" do %>
                <%= icon "flag-line" %>
                <%= t("actions.moderate", scope: "decidim.admin") %>
              <% end %>
            </li>

            <hr>
          <% end %>

          <% if allowed_to? :soft_delete, :assembly, trashable_deleted_resource: assembly %>
            <% if assembly.published? %>
              <li class="dropdown__item">
                <div class="dropdown__button-disabled">
                  <%= with_tooltip t("tooltips.deleted_assemblies_info", scope: "decidim.admin") do %>
                    <%= icon "delete-bin-line", class: "text-gray" %>
                    <span>
                      <%= t("actions.soft_delete", scope: "decidim.admin") %>
                    </span>
                  <% end %>
                </div>
              </li>
            <% else %>
              <li class="dropdown__item">
                <%= link_to soft_delete_assembly_path(assembly), class: "dropdown__button", method: :patch, data: { confirm: t("actions.confirm_delete_assembly", scope: "decidim.admin") } do %>
                  <%= icon "delete-bin-line" %>
                  <%= t("actions.soft_delete", scope: "decidim.admin") %>
                <% end %>
              </li>
            <% end %>
          <% end %>
        <% end %>
      </ul>
    </div>
  </td>
</tr>
